<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>菜单列表</title>
<load href="__PUBLIC__/css/bootstrap.min.css" />
<load href="__PUBLIC__/css/main.css" />
<load href="__PUBLIC__/js/jquery-1.9.1.min.js" />
<load href="__PUBLIC__/js/main.js" />
<script type="text/javascript">
$(function(){
	$("select[name='typearray']").change(function(){
		var v = $(this).children('option:selected').val();
		var p = "__ACTION__/id/"+v+".html";
		location.href=p;
	})
})
</script>
</head>

<body>
<style type="text/css">
.seoption{padding-top:10px; text-align:center;}
.seoption select{border:solid 1px #ccc; float:left; border-radius:3px; height:30px; font-size:12px; line-height:24px; border-right:none;}
button.okglian{display:block; clear:both; width:70px; margin:0px auto; margin-top:6px; background:none; background-color:#ff5454; color:#fff; border:none; border-radius:5px; line-height:22px; cursor:pointer;}
a.cancelgl{background-color: #666; padding: 5px 8px; float: right; margin-right: 10px; margin-top: -4px; color: #fff; border-radius: 3px; cursor: pointer; font-size: 12px;}
a.cancelgl:hover{background-color: #ff5454;}
</style>
<!-- 预览窗口开始 -->
<div class="previewbg" style="display:none;">
	<span style="margin-top:100px;"></span>
	<input></input>
	<iframe id="previewwidnow" src="" frameborder="0" scrolling="auto"></iframe>
</div>

<div class="jiumabg">
	<div class="jiuma" style="width:272px; height:115px; margin-top:200px;">
    	<div class="jiumaclose" style="background-color:#333;">X</div>
		<div class="jiuma_from"><input name='searkey' type="text" placeholder="按某个码的名称搜索" /><a id="searchsubmit">搜索</a></div>
		<div class="jiumalist seoption">
			<input type="hidden" name="preid" class="preid" />
            <span class="fl cnt" style="display:block; overflow:hidden;">
                <select name="typeid" class="template form-control" style="width:140px;">
                    <volist name='wymaselect' id='v'>
                    <option value="{$v.id}">{$v.typename}</option>
                    </volist>
                </select>
                <select name="menuid" class="template form-control" style="margin-left:-4px; border-left:none; border-right:solid 1px #ccc; width:110px;"></select>
            </span>
            <button class="okglian">确定关联</button>
                        
        </div>
	</div>
</div>
<!-- 预览窗口结束 -->
<div class="main-frame">
	<div class="position">华人码 > 华人码菜单列表</div>
	<div class="position-content">
		<div class="position-title">
			所属物语码及企业：<b>{$typearray.typename}</b>
		</div>
		<select name="typearray" class="form-control other-ma">
			<volist name='typeallarray' id='v'>
			<option value="{$v.id}" <if condition="$v['id'] eq $typearray['id']">selected</if>>{$v.typename}</option>
			</volist>
		</select>
	</div>
	<div class="table-list">
	 <table width="100%" border="1" cellspacing="0" cellpadding="0">
		    <tr class="th-bg">
		      <th width="5%">ID</th>
		      <th width="25%">菜单名称</th>
		      <th width="15%">绑定</th>
		      <th width="10%">别名</th>
		      <th width="8%">对应类型</th>
		      <th width="12%">创建时间</th>
		      <!-- <th width="7%">状态</th> -->
              <th width="6%">排序</th>
		      <th width="10%" style="text-align:right;">操作</th>
	        </tr>
	        {$submenuresult}
      </table>
    </div>
	<if condition="$Thinkphp.session.userinfo.type eq 1">
		<div class="operation"><a href="{:U('menuadd',array('rootid'=>I('get.id')))}" class="menuadd">添加菜单</a> <a onclick="history.go(-1);" style="cursor:pointer;">返回</a></div>
	</if>
</div>
<script type="text/javascript">
$(function(){
	
	$("#searchsubmit").click(function(){
		var key = $("input[name='searkey']").val();
		if($.trim(key)!=""){
			$.post("{:U('Index/gettypedata')}", {key:key,random:Math.random()}, function(data){
			   if(data!=0){
				   $("select[name='typeid']").html(data);
				   var wymaselect = $("select[name='typeid']");
				   if(wymaselect.val()!=""){
					   showsubmenu(wymaselect.val());
					   $("select[name='typeid']").css({"border-right":"none"});
					   $("select[name='menuid']").show(); 
					   $("button.okglian").show();
				   }else{
					   $("select[name='typeid']").css({"border-right":"solid 1px #ccc"});
					   $("select[name='menuid']").hide();
					   $("button.okglian").hide();    
				   }
				   
			   }
			})
		}
	})
	
	$("button.okglian").click(function(){
		var typeid = $("select[name='typeid']").val();
		var menuid = $("select[name='menuid']").val();
		if(menuid > 0 && typeid > 0){
			var preid = $(".preid").val();
			if(preid!=0 || preid!=""){
				$.get("{:U('Index/cpcolumndata')}", {preid:preid,typeid:typeid,menuid:menuid,random:Math.random()}, function(data){
					if(data==1){
						alert('关联成功！');
						//location.href='/Admin/Index/articlelist';
					}else if(data==2){
						alert('已经关联过！');
					}else{
						alert('关联失败');
					}
				})
			}
		}
	})

	function getTypestr(strpath){
		$.get(strpath, function(result){
			$("select[name='menuid']").html(result);
		});
	}
	var wymaselect = $("select[name='typeid']");
	function showsubmenu(val){
		var typeID = val;
		if(typeID>0){
			getTypestr("/Admin/Index/articleadd/rootid/"+typeID);
		}	
	}
	showsubmenu(wymaselect.val());
	wymaselect.change(function(){
		var v = $(this).val();
		showsubmenu(v);
	})

	
	$(".guanlian").each(function(index, element) {
        var t = $(this);
		t.find("span").click(function(){
			var getarticleID = $(this).attr("v");
			$(".jiumabg").fadeIn();
			$(".jiumabg .jiuma").show();
			$("input[name='preid']").val(getarticleID);
		})
    });	
	$(".jiumaclose").click(function(){
		$(".preid").val(null);
		$(".jiumabg .jiuma").hide();
		$(".jiumabg").fadeOut();
	})
})
</script>
</body>
</html>
